import rand from './rand.js';
class Chromosome {
  constructor(matrixNum, maxNodeNum) {
    this.rnvec = new Array(maxNodeNum);
    this.factorialCosts = new Array(matrixNum).fill(-1);
    this.factorialRanks = new Array(matrixNum).fill(-1);
    this.skillFactor = -1;
    this.scalarFitness = -1;
  }
  initialize(matrix) {
    const len = matrix.length;
    for (let i = 0; i < this.rnvec.length; i++) {
      this.rnvec[i] = rand(0, this.rnvec.length - 1);
    }
    for (let i = 0; i < len; i++) {
      let linkNodes = [];
      let j;
      for (j = 0; j < len; j++) {
        if (matrix[i][j] === 1 && i !== j) {
          if (this.rnvec[i] === this.rnvec[j]) {
            break;
          } else {
            linkNodes.push(j);
          }
        }
      }
      if (j === len && linkNodes.length !== 0) {
        this.rnvec[i] = this.rnvec[linkNodes[rand(0, linkNodes.length - 1)]];
      }
    }
  }
}
export default Chromosome;
